package com.engr.lyx.blog.biz.controller;

import com.engr.lyx.blog.biz.service.TagService;
import com.engr.lyx.common.annotation.FreeAccess;
import com.engr.lyx.common.base.ResultBody;
import com.engr.lyx.common.security.UserHelper;
import com.engr.lyx.common.security.UserProfileDetails;
import com.engr.lyx.common.utils.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: blog
 * @description: 个性标签管理
 * @author: lyx
 * @create: 2019-06-23
 **/
@Api(tags = "标签模块")
@RestController
@RequestMapping(value = "/api/tag")
public class TagController {

    @Autowired
    private TagService tagService;

    @FreeAccess
    @GetMapping(value = "/list")
    @ApiOperation(value = "查找所有标签",notes = "查找个人添加的所有标签,默认查找管理员")
    public ResultBody findAllTagsByUser(){

        // 获取token对应的userId
        UserProfileDetails userProfileDetails = UserHelper.getUserAuth();
        return ResultUtils.success(tagService.selectTagsByUserId(userProfileDetails == null ? 1L : userProfileDetails.getUserId()));
    }

    @FreeAccess
    @GetMapping(value = "/{id}/detail")
    @ApiOperation(value = "根据tagId查找",notes = "根据tagId查找")
    public ResultBody findTagById(@PathVariable long id){

        return ResultUtils.success(tagService.selectTagById(id));
    }

}
